import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import VueAutoImport from 'unplugin-auto-import/vite'
import { fileURLToPath, URL } from 'node:url'
// https://vitejs.dev/config/
export default defineConfig({
    envPrefix: 'HY', //为自定义开头名
    plugins: [
        uni(),
        VueAutoImport({
            // 引入的文件类型
            include: [
                /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
                /\.vue$/,
                /\.vue\?vue/, // .vue
            ],
            // 全局导入注册
            imports: [
                // 预设引入npm包
                'vue',
                'uni-app',
                'pinia',
                'vue-router',
            ],
            dts: 'src/auto-import.d.ts',
            eslintrc: {
                enabled: true, // Default `false`
                filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
                globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
            },
        }),
    ],
    build: {
        // 开发阶段启用源码映射：https://uniapp.dcloud.net.cn/tutorial/migration-to-vue3.html#需主动开启-sourcemap
        sourcemap: process.env.NODE_ENV === 'development',
        // minify: 'terser',
        // // 发布时删除 console
        // terserOptions: {
        //   compress: {
        //     drop_console: true,
        //   },
        // },
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
        },
    },
    server: {
        host: '0.0.0.0',
        port: 8088, //启动端口
        proxy: {
            '/api': {
                target: 'http://192.168.10.102:8080',
                changeOrigin: true,
                //类比与webpack里面的pathRewrite
                rewrite: (path) => path.replace(/^\/api/, ''),
            },
            '/formalapi': {
                target: 'https://hongcai365.com',
                changeOrigin: true,
                //类比与webpack里面的pathRewrite
                rewrite: (path) => path.replace(/^\/formalapi/, ''),
            },
        },
    },
})
